<template>
  <div class="goods-relevant">
    <div class="header">
      <i class="icon"></i>
      <span class="title">{{goodsId?'同类商品推荐':'猜你喜欢'}}</span>
    </div>
    <!-- 此处使用改造后的tizi-carousel.vue -->
    <TiziCarousel :sliders="sliders" style="height:380px" auto-play/>
  </div>
</template>

<script>
import {findRelGoods} from '@/api/product'
import {ref} from 'vue'
// 得到需要的数据
const useRelGoodsData = (id) => {
  const sliders = ref([])
  findRelGoods(id).then(data => {
    // 每页4条
    const size = 4
    const total = Math.ceil(data.result.length / size)
    for (let i = 0; i< total;i++) {
      sliders.value.push(data.result.slice(i*size, (i+1)*size))
    }
  })
  return sliders
}
export default {
    // 同类推荐，猜你喜欢 模块
    name:'GoodsRelevant',
    props: {
      goodsId : {
        type:String,
        default:undefined
      }
    },
    setup(props) {
      const sliders = useRelGoodsData(props.goodsId)
      return {sliders}
    }
}
</script>

<style lang="less" scoped>
.goods-relevant {
    background: #fff;
    min-height: 460px;
    margin-top: 20px;
    .header {
      height: 80px;
      line-height: 80px;
      padding: 0 20px;
      .title {
        font-size: 20px;
        padding-left: 10px;
      }
      .icon {
        width: 16px;
        height: 16px;
        display: inline-block;
        border-top: 4px solid #fef284;
        border-right: 4px solid #fef284;
        box-sizing: border-box;
        position: relative;
        transform: rotate(45deg);
        &::before {
          content: '';
          width: 10px;
          height: 10px;
          position: absolute;
          left: 0;
          top:2px;
          background: #a8dacf;
        }
      }
    }
}
// 覆盖轮播图的新样式
:deep(.tizi-carousel) {
  height: 380px;
  .carousel {
    &-indicator {
      bottom: 30px;
      span {
        &.active {
          background: #fef284;
        }
      }
    }
    &-btn {
      top: 110px;
      // 鼠标放上显示
      // opacity: 1;
      background: rgba(0,0,0,0);
      color: #ddd;
      i {
        font-size: 30px;
      }
    }
  }
}
</style>